package com.example.l3.ktm.ListView;

import java.util.List;

import com.example.l3.ktm.R;
import com.example.l3.ktm.R.id;
import com.example.l3.ktm.R.layout;

import android.content.Context;
import android.content.res.Resources.Theme;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CustomCellAdapter extends ArrayAdapter<CellDataItem> {

	List<CellDataItem> listCellDataItems;
	private TextView stt;
	private TextView fileName;
	public TextView percent;
	
	public CustomCellAdapter(Context context, int textViewResourceId, List<CellDataItem> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
		listCellDataItems = objects;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listCellDataItems.size();
	}
	
	@Override
	public CellDataItem getItem(int position) {
		// TODO Auto-generated method stub
		return listCellDataItems.get(position);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View view = convertView;
		final CellDataItem dataItem = listCellDataItems.get(position);
		
		if(view == null) {
			LayoutInflater layoutInflater = LayoutInflater.from(getContext());
			view = layoutInflater.inflate(R.layout.listview_cell, null);
			stt = (TextView) view.findViewById(R.id.txtSTT);
			fileName = (TextView) view.findViewById(R.id.txtFileName);
			percent = (TextView) view.findViewById(R.id.txtPercent);
			
			dataItem._textView = percent;
			
			if(stt != null) {
				stt.setText(Integer.valueOf(position).toString());
			}
			if(fileName != null) {
				fileName.setText(dataItem.getFileName());
			}
			if(percent != null) {
//				percent.setText(String.valueOf(dataItem.getNumOfByte() / 1024) + " KB");
				
			}
		}
		
		
		return view;
	}
}
